#ifndef __CORE_THREAD_H__
#define __CORE_THREAD_H__

#include <Windows.h>
#include <string>
#include "Mutex.h"

namespace Core
{
#define DEFAULT_THREAD_STACK_SIZE		(256 * 1024)
	enum ThreadPriority 
	{
		PRIORITY_MAX,
		PRIORITY_HIGH,
		PRIORITY_NOMINAL,
		PRIORITY_LOW,
		PRIORITY_MIN,
		PRIORITY_DEFAULT
	};

	class rtThread
	{
	public:
		rtThread(void);
		virtual ~rtThread(void);

		std::string    getName();
		ThreadPriority getThreadPriority();
		void           setThreadPriority(ThreadPriority priority);
		HANDLE         getThreadHandle();
		bool           isRunning();
		bool           isTerminating();

		virtual bool   startThread(std::string name, ThreadPriority priority, int stackSize = DEFAULT_THREAD_STACK_SIZE);
		void           stopThread(bool bWait = true);
		void           waitForThread();

	protected:
		virtual int run() = 0;
	private:

		static int ThreadRountine(rtThread* pThread);
		void       createThread();
		void       destroyThread();
		std::string     m_Name;
		HANDLE          m_ThreadHandle;
		ThreadPriority  m_ThreadPriority;
		int             m_StackSize;
		bool            m_IsRunning;
		volatile bool   m_IsTerminating;
	};
}

#endif


